package org.dromara.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.XfCompany;
import org.dromara.system.domain.XfNews;
import org.dromara.system.domain.XfRatingDimension;
import org.dromara.system.domain.query.XfRatingDimensionQuery;
import org.dromara.system.domain.vo.XfNewsVo;
import org.dromara.system.domain.vo.XfRatingDimensionVo;
import org.dromara.system.mapper.XfCompanyMapper;
import org.dromara.system.mapper.XfRatingDimensionMapper;
import org.dromara.system.service.IXfCompanyService;
import org.dromara.system.service.IXfRatingDimensionService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XfRatingDimensionServiceImpl extends ServiceImpl<XfRatingDimensionMapper, XfRatingDimension> implements IXfRatingDimensionService {

    @Override
    public TableDataInfo<XfRatingDimensionVo> selectPageXfRatingDimensionList(XfRatingDimensionQuery query) {
        Page<XfRatingDimension> page = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<XfRatingDimension> wrapper = Wrappers.lambdaQuery();

        // 根据ID查询
        wrapper.eq(query.getId() != null, XfRatingDimension::getId, query.getId());

        // 根据状态查询
        wrapper.eq(query.getStatus() != null, XfRatingDimension::getStatus, query.getStatus());

        // 按创建时间降序排列
        wrapper.orderByDesc(XfRatingDimension::getCreatedAt);

        Page<XfRatingDimensionVo> result = baseMapper.selectPageXfRatingDimensionList(page, wrapper);
        return TableDataInfo.build(result);
    }

    @Override
    public List<XfRatingDimensionVo> selectXfRatingDimensionList(XfRatingDimensionQuery query) {
        return baseMapper.queryList(query);
    }

    @Override
    public XfRatingDimensionVo selectXfRatingDimensionById(Long id) {
        return baseMapper.selectVoById(id);
    }

    @Override
    public boolean insertXfRatingDimension(XfRatingDimension ratingDimension) {
        return this.save(ratingDimension);
    }

    @Override
    public boolean updateXfRatingDimension(XfRatingDimension ratingDimension) {
        return this.updateById(ratingDimension);
    }

    @Override
    public int deleteXfRatingDimensionById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int deleteXfRatingDimensionByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(List.of(ids));
    }
}
